import Vue from 'vue'

// 导入ElementUI
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

import App from './App.vue'
import router from './router'
import store from './store'
import importDirective from './directive'
import axios from 'axios'
// import VueContextMenu from '@xunlei/vue-context-menu'
// import VueCookies from 'vue-cookies'
import VueAxios from 'vue-axios'

// import http from './utils/http' // 引入请求工具

// Vue.use(VueContextMenu)

Vue.use(ElementUI)
Vue.use(importDirective)
Vue.config.productionTip = false
Vue.use(VueAxios, axios)
// Vue.use(VueCookies)
// require('./mock')
Object.defineProperty(Vue.prototype, '$axios', { value: axios })

Vue.prototype.post = function (url, dist, methodSucc) {
  Vue.axios.post(url, dist, {
    headers: {
      // 'X-CSRFToken': this.$cookies.get('csrftoken'),
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
      .then((response) => {
        methodSucc(response)
      })
      .catch((error) => {
        console.log(error)
        this.$message.error('请求错误')
      })
}



router.beforeEach((to, from, next) => {//beforeEach是router的钩子函数，在进入路由前执行
    if (to.meta.title) {//判断是否有标题
        console.log(to.meta.title)
        document.title = to.meta.title
    }
    next()
})
Vue.directive('title', {//单个修改标题
    inserted: function (el) {
        document.title = el.dataset.title
    }
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
